import React from "react"
import { Card, Button } from 'antd';
import { createStore } from 'redux'; //01
import Redux from "./reduxs"
let store = createStore(Redux);
class Redux01 extends React.Component {
    constructor(props) {
        super(props);
        store.subscribe(() => {
            this.setState({
                num: store.getState()
            })
        }
        );
        this.state = {
            num: store.getState()
        }
    }

    render() {
        return (
            <Card title="Redux 基本操作" bordered={false}>
                <div>
                    <h2>{this.state.num}</h2>
                    <div className="margin_top_sm">
                        <Button onClick={() => { store.dispatch({ type: 'INCREMENT' }) }} className="margin_right_sm" type="primary">增加</Button>
                        <Button onClick={() => { store.dispatch({ type: 'DECREMENT' }) }} type="primary">减少</Button>
                    </div>
                </div>
            </Card>
        )
    }
}
export default Redux01